package components
{
	import components.Tips;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObjectContainer;
	import flash.display.InteractiveObject;
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.filters.BlurFilter;
	import flash.geom.Matrix;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.system.ApplicationDomain;
	import flash.text.TextField;
	import flash.display.DisplayObject;

	public class MyTips extends Tips
	{
		private var pos:Point;
		public function MyTips(obj:DisplayObject, text:String, filterAlpha:Boolean=false, stopOverTimer:int=0,auto:Boolean=true,pos:Point = null)
		{
			pos=pos;
			super(obj, text, filterAlpha, stopOverTimer,auto); 	
		}
		override protected function resetPostion():void{
			if(pos){
				if(toolTips.parent==null){
					var localP:Point = target.localToGlobal(pos);
					toolTips.x=localP.x;
					toolTips.y=localP.y;
					show(toolTips);
				}
			}else{
			    super.resetPostion();
			}
		}
		/**
		 * 根据需求可重写此方法,修改text属性将会触发此方法的调用。
		 * @param contain tips显示容器
		 * @param text 要显示的文件。
		 */
		override protected function draw(contain:Sprite,text:*):void{
			while(contain.numChildren>0){
				contain.removeChildAt(0);
			}
			var t:TextField=new TextField();
			t.multiline=true;
			t.textColor=0xffffff;
			t.htmlText=text;
			t.x=8;
			t.y=5;
			t.width=t.textWidth+8;
			t.height=t.textHeight+10;
			contain.addChild(t);
			var c:*=ApplicationDomain.currentDomain.getDefinition("UI_tips_Bg");
			var bg:Sprite=new c();
			bg.width=t.width+11;
			bg.height=t.height+3;
			contain.addChildAt(bg,0);
			cs=contain;
		}
//		
//		public var pos:Boolean
//		override protected function resetPostion():void
//		{
//		    if(pos){
//			   super.resetPostion();
//			}	
//		}
//		
		public function get mc():DisplayObjectContainer
		{
			return toolTips;
		}
		/*override protected function onMouseOver(e:MouseEvent):void
		{
			super.onMouseOver(e);
			e.stopPropagation();
		}*/
		
		private var cs:Sprite
		private var sceneBg:Bitmap=new Bitmap();
//		override protected function resetPostion():void{
//			if(target.stage==null || SocialGame.self.mainUI==null){
//				return;
//			}
//			super.resetPostion();
//			
////			var st:String=SocialGame.self.mainUI.modelState
////			if(st!=UIManager.MODEL_FIGHTING && st!=UIManager.MODEL_FULL_FIGHTING && SocialGame.self.usrInfo.level<10){
////				onEnter();// 效果。
////			}
//			
//		}
		private function onEnter(e:Event=null):void{
			var sg:Stage=target.stage;
			if(sg==null) return;
			if(cs==null) return;
			var bitmapMapData:BitmapData=new BitmapData(cs.width,cs.height,false,0);
			var m:Matrix=new Matrix();
			m.tx=-cs.x;
			m.ty=-cs.y;
			cs.visible=false;
			try{
				bitmapMapData.draw(sg,m,null,null,new Rectangle(0,0,cs.width,cs.height));
			}catch(e:Error){
				trace(e);
			}
			cs.visible=true;
			
			sceneBg.bitmapData=bitmapMapData;
			if(sceneBg.filters!=null){
				sceneBg.filters=[new BlurFilter(5,5,3)];
			}
			cs.addChildAt(sceneBg,0);  
		}
	}
}